package com.sjd.web.api.farm;

import com.sjd.common.core.controller.BaseController;
import com.sjd.common.core.domain.AjaxResult;
import com.sjd.common.core.page.TableDataInfo;
import com.sjd.farm.domain.dto.order.WxFarmOrderCreateRequestDTO;
import com.sjd.farm.domain.dto.order.WxFarmOrderQryResponseDTO;
import com.sjd.farm.service.WxFarmOrderService;
import com.sjd.mall.domain.dto.base.OrderNoRequestDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * WxFarmOrderApi
 *
 * @author seer
 * @version 1.0
 * @date 2022/2/5 13:51
 */
@Api(tags = "农场订单模块(小程序)")
@Slf4j
@RestController
@RequestMapping("/weixin/api/farm/order")
public class WxFarmOrderApi extends BaseController {

    @Autowired
    private WxFarmOrderService service;

    /**
     * 订单创建
     *
     * @param requestDTO requestDTO
     * @return object
     */
    @ApiOperation(value = "订单创建")
    @PostMapping(value = "/create")
    public AjaxResult create(@Validated @RequestBody WxFarmOrderCreateRequestDTO requestDTO) {
        log.info("订单创建,请求 {}", requestDTO);
        AjaxResult result = service.create(requestDTO);
        log.info("订单创建,响应 {}", result);
        return result;
    }

    /**
     * 订单支付
     *
     * @param requestDTO requestDTO
     * @return object
     */
    @ApiOperation(value = "订单支付")
    @PostMapping(value = "/pay")
    public AjaxResult pay(@Validated @RequestBody OrderNoRequestDTO requestDTO) {
        log.info("订单支付,请求 {}", requestDTO);
        AjaxResult result = service.pay(requestDTO);
        log.info("订单支付,响应 {}", result);
        return result;
    }

    /**
     * 订单查询
     *
     * @return object
     */
    @ApiOperation(value = "订单查询")
    @GetMapping("/qry")
    private TableDataInfo qry() {
        startPage();
        if (log.isDebugEnabled()) {
            log.debug("订单查询");
        }
        List<WxFarmOrderQryResponseDTO> respList = service.qry();
        if (log.isDebugEnabled()) {
            log.debug("订单查询,响应 {}", respList);
        }
        return getDataTable(respList);
    }
}
